import { RequestUtil } from '@/utils/request.js';

const login = ({ username, password }) => {
  return RequestUtil.get('/login', {
    params: {
      username,
      password
    }
  });
};

const logout = () => {
  return RequestUtil.get('/logout');
};

const getLoginUser = (requestId) => {
  return RequestUtil.get('/getLoginUser', {
    requestId: requestId
  });
};

const getUserList = (pageNo, pageSize, query, sortBy, isAsc) => {
  return RequestUtil.get('/user', {
    params: {
      pageNo,
      pageSize,
      sortBy: sortBy,
      isAsc: isAsc,
      ...query
    }
  });
};

const add = (user) => {
  return RequestUtil.post('/user', {
    data: user
  });
};

const update = (id, user) => {
  return RequestUtil.put('/user', {
    data: { userId: id, ...user }
  });
};

const deleteByIds = (ids) => {
  return RequestUtil.delete(`/user/${ids.join(',')}`);
};

export const UserApi = {
  login,
  getLoginUser,
  logout,
  getUserList,
  add,
  update,
  deleteByIds
};
